﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using ITProject.Domain.Entities;
using ITProject.WebUI.Models.Project;
using ITProject.WebUI.Models.ProjectAdmin;

namespace ITProject.WebUI.Models.ProjectUser
{
    public class ProjectUserMyFeatureDetailsViewModel
    {
        [Display(Name = "Nazwa")]
        public string Name { get; set; }
        [Display(Name = "Status")]
        public string Status { get; set; }
        [Display(Name = "Priorytet")]
        public string Priority { get; set; }
        [Display(Name = "Planowana data zakończenia")]
        public string PlannedEndDate { get; set; }
        [Display(Name = "Opis")]
        public string Description { get; set; }
        [Display(Name = "Data rozpoczęcia")]
        public string StartDate { get; set; }
        [Display(Name = "Wersja")]
        public string Release { get; set; }

        public StatusChangeViewModel[] FeatureStatusChanges { get; set; }

        // ukryte
        public int FeatureId { get; set; }

        public static ProjectUserMyFeatureDetailsViewModel Convert(Feature feature, StatusChange[] scTab, string[] userStatusChangeTab, string ReleaseName="")
        {
            ProjectUserMyFeatureDetailsViewModel vm = new ProjectUserMyFeatureDetailsViewModel();
            vm.Priority = PriorityViewModel.ConvertFromByte(feature.Priority);
            vm.Status = StatusName.ConvertFromByte(feature.Status);
            vm.Name=feature.Name;
            vm.Description = feature.Description;
            vm.PlannedEndDate = feature.PlannedEndDate.ToLongDateString();
            vm.StartDate = feature.StartDate.ToLongDateString();
            if (ReleaseName == "")
                vm.Release = ProjectAdminAddNewFeatureViewModel.NoRelease;
            else
                vm.Release = ReleaseName;
            vm.FeatureStatusChanges = new StatusChangeViewModel[scTab.Length];
            for (int i = 0; i < scTab.Length; i++)
                vm.FeatureStatusChanges[i] = new StatusChangeViewModel
                {
                    Comment = scTab[i].Comment,
                    DateOfChange = scTab[i].DateOfChange,
                    User = userStatusChangeTab[i],
                    OldStatus = StatusName.ConvertFromByteNullable(scTab[i].OldStatus),
                    NewStatus = StatusName.ConvertFromByte(scTab[i].NewStatus)
                };
            return vm;
        }
    }
}